package com.example.demo.web.Controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.net.URI;

/**
 * @Auther: hjy(lc))
 * @Date: 2022/11/3-11-03-11:39
 * @Description：com.example.demo.web.Controller
 */
@RestController
public class HelloController {
    @Autowired
    private RestTemplate restTemplate;
    @GetMapping("/hello")
    public String hello(){
        //结果来自 localhost:9999/hello 返回的结果
        //url 对方服务的接口路径
        //String.class  对方返回的参数类型
        URI url;
        //        String afterReresult = restTemplate.getForObject(url, String.class);
        ResponseEntity<String> forEntity = restTemplate.getForEntity("http://localhost:9999/hello", String.class);
        String body = forEntity.getBody();
        System.out.println("body = " + body);
        return body;
    }
}
